package com.atguigu.gmallre.mock.service.impl;

import com.atguigu.gmallre.mock.bean.*;
import com.atguigu.gmallre.mock.mapper.*;
import com.atguigu.gmallre.mock.service.*;
import com.atguigu.gmallre.mock.service.adv.impl.AdvServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 商品收藏表 服务实现类
 * </p>
 *
 * @author zhangchen
 * @since 2020-02-24
 */
@Service
@Slf4j
public class FavorInfoServiceImpl extends AdvServiceImpl<FavorInfoMapper, FavorInfo> implements FavorInfoService {

    @Autowired
    SkuInfoMapper skuInfoMapper;

    @Autowired
    UserInfoMapper userInfoMapper;


    Map<Long, List<FavorInfo>> favorInfoByUserMap=new HashMap<>();

    @PostConstruct
    protected void loadCache(){
        List<FavorInfo> list = list();
        for (FavorInfo favorInfo : list) {
            List<FavorInfo> favorInfoList = favorInfoByUserMap.get(favorInfo.getUserId());
            if(favorInfoList==null){
                favorInfoList = new ArrayList<>();
            }
            favorInfoList.add(favorInfo);
            favorInfoByUserMap.put(favorInfo.getUserId(),favorInfoList);
        }

    }

    public List<FavorInfo> getFavorInfoListByUserId(Long userId){
        return favorInfoByUserMap.get(userId);
    }




}
